import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig({
  server: {
    port: 8888,
    open: true,
    proxy: {
      '/api': {
        target: 'https://xly.shclkj.com/hufu/api/v1/restData/', // 目标地址
        changeOrigin: true, // 修改请求头的 Origin 字段
        rewrite: (path) => path.replace(/^\/api/, '')  // 重写路径
      },
    }
  },
  plugins: [
    vue(),
    vueJsx(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@c': fileURLToPath(new URL('./src/components', import.meta.url)),
      '@api': fileURLToPath(new URL('./src/api', import.meta.url)),
    },
  },
})
